package com.samphanie.auiu

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenCreated
import androidx.lifecycle.whenResumed
import androidx.lifecycle.whenStarted
import com.samphanie.auiu.demo.banner.AuiuBannerDemoActivity
import com.samphanie.auiu.demo.concurrent.coroutine.CoroutineScene
import com.samphanie.auiu.demo.concurrent.coroutine.CoroutineScene3
import com.samphanie.auiu.demo.log.AuiuLogDemoActivity
import com.samphanie.auiu.demo.refresh.AuiuRefreshDemoActivity
import com.samphanie.auiu.demo.tab.AuiuTabBottomDemoActivity
import com.samphanie.auiu.demo.tab.AuiuTabTopDemoActivity
import kotlinx.coroutines.async
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onClick(v: View?) {
        when (v!!.id) {

            R.id.tv_log -> {
                startActivity(Intent(this, AuiuLogDemoActivity::class.java))
            }
            R.id.tv_auiu_refresh -> {
                startActivity(Intent(this, AuiuRefreshDemoActivity::class.java))
            }
            R.id.tv_tab_bottom -> {
                startActivity(Intent(this, AuiuTabBottomDemoActivity::class.java))
            }
            R.id.tv_auiu_taptop -> {
                startActivity(Intent(this, AuiuTabTopDemoActivity::class.java))
            }
            R.id.tv_auiu_banner -> {
                startActivity(Intent(this, AuiuBannerDemoActivity::class.java))
            }
            R.id.tv_coroutine -> {
                lifecycleScope.launch {
                    val content = CoroutineScene3.parseAssetsFile(assets, "main_tabs_config.json")
                    Log.e("coroutine", content)
                }
                Log.e("coroutine", "after click")

//                lifecycleScope.async {  }
//                lifecycleScope.launchWhenCreated {
//                    // 当宿主的生命周期 至少为onCreate的时候 才会启动
//                    whenCreated {
//                        // 当宿主的生命周期 为onCreate的时候 才会执行 否则都是暂停
//                    }
//                    whenResumed {
//                        // 当宿主的生命周期 为onResume的时候 才会执行
//                    }
//                    whenStarted {
//                        // 当宿主的生命周期 为onStart的时候 才会执行
//                    }
//                }
            }
        }
    }
}